//
//  BaseWeibo.m
//  NewsReader
//
//  Created by blacksun on 11-3-1.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "BaseWeibo.h"


@implementation BaseWeibo
@synthesize oauthKey;
@synthesize userId;
@synthesize userName;

- (void)parseTokenKeyWithResponse:(NSString *)aResponse{
	NSDictionary *params = [NSURL parseURLQueryString:aResponse];
	self.oauthKey.tokenKey = [params objectForKey:@"oauth_token"];
	self.oauthKey.tokenSecret = [params objectForKey:@"oauth_token_secret"];
}

- (void)parseOAuthVerifier:(NSString *)queryStr{
	self.oauthKey.verify = [self valueForKey:k_Oauth_Verifier ofQuery:queryStr];
	NSLog(@"verify=%@",oauthKey.verify);
}

-(NSString*) valueForKey:(NSString *)key ofQuery:(NSString*)query{
	NSArray *pairs = [query componentsSeparatedByString:@"&"];
	for(NSString *aPair in pairs){
		NSArray *keyAndValue = [aPair componentsSeparatedByString:@"="];
		if([keyAndValue count] != 2) continue;
		if([[keyAndValue objectAtIndex:0] isEqualToString:key]){
			return [keyAndValue objectAtIndex:1];
		}
	}
	return nil;
}

-(void)dealloc{
	self.oauthKey = nil;
    self.userName = nil;
    self.userId = nil;
	[super dealloc];
}


//空方法，在子类中被覆盖
-(void) getRequestToken{}
-(NSURLRequest *) getAuthorizaRequest{return nil;}
-(void) getAccessToken{}
-(void) getUserName{}
-(void) saveAccessToken{}
//发送微薄
-(BOOL) sendTweet:(NSString *)tweet{return NO;}


@end
